<template>
	<view>
		<view class="form_split_10"></view>
		<u-empty text="没有找到对应的数据" v-if="show_empty === true" />
		<view>
			<view class="list_wrapper">
				<view v-for="(item, index) in dataset" :key="index">
					<view class="list">
						<view class="tx1">{{ item.content }}</view>
						<view class="tx3">{{ item.addtime | timeFilter }}</view>
					</view>
					<view class="form_split_10"></view>
				</view>
			</view>
			<!-- <u-list  v-model="loading" :finished="finished" :finished-text="finished_text" @load="onLoad" :immediate-check="true"></u-list> -->
			<u-loadmore class="u-loadmore" v-if="dataset.length > params.pagesize" :status="finished_status" />
		</view>

	</view>
</template>

<script>
	import {
		parseTime
	} from '@/utils/index'
	import http from '@/utils/http'
	import api from '@/api'
	export default {
		name: 'SetmealLog',
		filters: {
			timeFilter(timestamp) {
				return parseTime(timestamp, '{y}-{m}-{d} {h}:{i}:{s}')
			}
		},
		data() {
			return {
				dataset: [],
				finished_status:'loadmore',
				show_empty: false,
				params: {
					page: 1,
					pagesize: 10
				}
			}
		},
		mounted() {
			this.fetchData(true)
		},
		onReachBottom(){
			this.params.page++
			this.fetchData(false) 
		},
		methods: {
			fetchData(init) {
				if (init === true) {
					this.params.page = 1 
				} else {
					this.finished_status = "loading"
				}
				http
					.get(api.company_setmeallog, this.params)
					.then(res => {
						if (init === true) {
							this.dataset = [...res.data.data.items]
						} else {
							this.dataset = this.dataset.concat(res.data.data.items)
						}
						// 数据全部加载完成
						if (res.data.data.items.length < this.params.pagesize) {
							this.finished_status = 'nomore'
							if (init === false) {
								this.finished_status = 'nomore'
							} else if (res.data.data.items.length === 0) {
								this.show_empty = true
							}
						}
					})
					.catch(() => {})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.list_wrapper {
		.list {
			.tx3 {
				padding-top: 10px;
				font-size: 13px;
				color: #999999;
			}

			.tx1 {
				padding-top: 15px;
				font-size: 14px;
				color: #333333;
				line-height: 22px;
			}

			width: 100%;
			padding: 0 17px 15px;
		}

		width: 100%;
		background-color: #ffffff;
	}
</style>
